/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package BL;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 *
 * @author sundas
 */
@Entity
@Table(name = "supplier", catalog = "newPurchase", schema = "", uniqueConstraints = {@UniqueConstraint(columnNames = {"supplierId"})})
@NamedQueries({@NamedQuery(name = "Supplier.findAll", query = "SELECT s FROM Supplier s"), @NamedQuery(name = "Supplier.findBySupplierId", query = "SELECT s FROM Supplier s WHERE s.supplierId = :supplierId"), @NamedQuery(name = "Supplier.findByCompanyName", query = "SELECT s FROM Supplier s WHERE s.companyName = :companyName"), @NamedQuery(name = "Supplier.findByCompanyContact", query = "SELECT s FROM Supplier s WHERE s.companyContact = :companyContact")})
public class Supplier implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "supplierId", nullable = false)
    private Integer supplierId;
    @Basic(optional = false)
    @Column(name = "companyName", nullable = false, length = 50)
    private String companyName;
    @Basic(optional = false)
    @Column(name = "companyContact", nullable = false, length = 50)
    private String companyContact;
    @ManyToMany(mappedBy = "supplierCollection")
    private Collection<Product> productCollection;
    @OneToMany(mappedBy = "supplierId")
    private Collection<Stock> stockCollection;
    @OneToMany(mappedBy = "supplierId")
    private Collection<Prodorder> prodorderCollection;
    @JoinColumn(name = "NIC", referencedColumnName = "NIC")
    @ManyToOne
    private Person nic;

    public Supplier() {
    }

    public Supplier(Integer supplierId) {
        this.supplierId = supplierId;
    }

    public Supplier(Integer supplierId, String companyName, String companyContact) {
        this.supplierId = supplierId;
        this.companyName = companyName;
        this.companyContact = companyContact;
    }

    public Integer getSupplierId() {
        return supplierId;
    }

    public void setSupplierId(Integer supplierId) {
        this.supplierId = supplierId;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getCompanyContact() {
        return companyContact;
    }

    public void setCompanyContact(String companyContact) {
        this.companyContact = companyContact;
    }

    public Collection<Product> getProductCollection() {
        return productCollection;
    }

    public void setProductCollection(Collection<Product> productCollection) {
        this.productCollection = productCollection;
    }

    public Collection<Stock> getStockCollection() {
        return stockCollection;
    }

    public void setStockCollection(Collection<Stock> stockCollection) {
        this.stockCollection = stockCollection;
    }

    public Collection<Prodorder> getProdorderCollection() {
        return prodorderCollection;
    }

    public void setProdorderCollection(Collection<Prodorder> prodorderCollection) {
        this.prodorderCollection = prodorderCollection;
    }

    public Person getNic() {
        return nic;
    }

    public void setNic(Person nic) {
        this.nic = nic;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (supplierId != null ? supplierId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Supplier)) {
            return false;
        }
        Supplier other = (Supplier) object;
        if ((this.supplierId == null && other.supplierId != null) || (this.supplierId != null && !this.supplierId.equals(other.supplierId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "DB.Supplier[supplierId=" + supplierId + "]";
    }

}
